import requests
from basic.base_request import baseAdminRequest
"""
后端卡密模块
"""
class URL:
    cdkey_List = '/api/admin/merchant/cdkey/library/page/list'
    cdkey_Save = '/api/admin/merchant/cdkey/library/save'
    cdkey_Update = '/api/admin/merchant/cdkey/library/update'
    cdkey_Delete = '/api/admin/merchant/cdkey/library/delete'
class AdminCdkey(baseAdminRequest,URL):
    def cdkey_list(self,name=None,productName=None):
        """
        获取卡密列表
        :param name: 卡密名称
        :param productName: 产品名称
        :return:
        """
        params = {
            'page': '1',
            'limit': '20',
            'name': name,
            'productName':productName,
            'temp': '1754051855',
        }
        return self.get(self.cdkey_list.__name__,self.cdkey_List,params)
    def cdkey_save(self,name=None,remark=None):
        """
        新增卡密
        :param name: 卡密名称
        :param remark: 卡密备注
        :return:
        """
        json_data = {
            'name': name,
            'remark': remark,
            'id': None,
            'usedNum': 0,
            'totalNum': 0,
            'createTime': '2025-08-01 16:16:55',
            'productName': '',
            'productAttrValueName': '',
        }
        return self.post(self.cdkey_save.__name__,self.cdkey_Save,json_data)
    def cdkey_update(self,name=None,remark=None,cdkey_update_id=None):
        """
        更新卡密
        :param cdkey_update_id: 卡密id
        :param name: 卡密名称
        :param remark: 卡密备注
        :return:
        """
        json_data = {
            'name': name,
            'remark': remark,
            'id': cdkey_update_id,
            'usedNum': 0,
            'totalNum': 0,
            'createTime': '2025-08-01 20:44:50',
            'productName': '',
            'productAttrValueName': '',
        }
        return self.post(self.cdkey_update.__name__,self.cdkey_Update,json_data)
    def cdkey_delete(self,cdkey_delete_id=None):
        json_data = {}
        url = self.cdkey_Delete + f"/{cdkey_delete_id}"
        return self.post(self.cdkey_delete.__name__,url,json_data)

